home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / include / scribus-ng / pdfoptionsio.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-07-23  |  4.8 KB  |  154 lines

  1. /*
  2. For general Scribus (>=1.3.2) copyright and licensing information please refer
  3. to the COPYING file provided with the program. Following this notice may exist
  4. a copyright and/or license notice that predates the release of Scribus 1.3.2
  5. for which a new license (GPL+exception) is in place.
  6. */
  7. #ifndef PDFOPTIONSIO_H
  8. #define PDFOPTIONSIO_H
  9.  
  10. #include <QDomElement>
  11. #include <QList>
  12.  
  13. #include "pdfoptions.h"
  14. #include "scribusapi.h"
  15.  
  16. /**
  17.  * @file pdfoptionsio.h
  18.  * @author Craig Ringer
  19.  */
  20.  
  21. /**
  22.  * @brief Helper class for reading/writing PDFOptions
  23.  * @author Craig Ringer
  24.  *
  25.  * PDFOptionsIO reads and writes PDFOptions to various
  26.  * formats. Currently only a custom XML format is
  27.  * supported, but support for reading/writing Adobe's
  28.  * .joboptions (for example) might be added in future.
  29.  *
  30.  * Usage:
  31.  *    // Writing:
  32.  *    // where `opts' is an existing PDFOptions instance
  33.  *    PDFOptionsIO io(opts);
  34.  *    if (!io.writeTo("/path/to/file"))
  35.  *       qDebug("Failed to save settings: %s", io.lastError.utf8());
  36.  *
  37.  *    // Reading:
  38.  *    PDFOptions opts;
  39.  *    PDFOptionsIO io(opts);
  40.  *    if (!io.readFrom("/path/to/file"))
  41.  *       qDebug("Failed to load settings: %s", io.lastError.utf8());
  42.  *
  43.  *  You should generally not keep PDFOptionsIO objects around;
  44.  *  just create an instance when you need it.
  45.  *
  46.  * @sa PDFOptions
  47.  */
  48. class SCRIBUS_API PDFOptionsIO
  49. {
  50. public:
  51.     /**
  52.      * @brief simple ctor
  53.      */
  54.     PDFOptionsIO(PDFOptions& opts);
  55.  
  56.     /**
  57.      * @brief Save the PDF settings to a file or other stream
  58.      *
  59.      * @warning unimplemented, always fails.
  60.      *
  61.      * @param outDevice QIODevice to write output to.
  62.      * @param includePasswords true if with passwords
  63.      * @return True for success.
  64.      */
  65.     bool writeTo(QIODevice& outDevice, bool includePasswords = false);
  66.     bool writeTo(QString outFileName, bool includePasswords = false);
  67.  
  68.     /**
  69.      * @brief Load the PDF settings from a file or other data stream, overwriting
  70.      *        any current settings
  71.      *
  72.      * @warning unimplemented, always fails
  73.      *
  74.      * @warning on failure, struct contents are undefined.
  75.      *
  76.      * @param inStream QIODevice to settings data from.
  77.      * @return True for success.
  78.      */
  79.     bool readFrom(QIODevice& inStream);
  80.     bool readFrom(QString inFileName);
  81.  
  82.     /**
  83.      * @brief Return human-readable explanation of last error.
  84.      * @warning Do not depend on particular values of this in your code.
  85.      */
  86.     const QString& lastError() const;
  87.  
  88. protected:
  89.     // Build and return an XML representation of the settings.
  90.     // QString::null is returned on failure, in which case
  91.     // the error string is set.
  92.     QString buildXMLString();
  93.  
  94.     // Populate the current DOM tree with the settings from the
  95.     // current PDFOptions instance.
  96.     void buildSettings();
  97.  
  98.     // Helper functions. Add elements under the root element
  99.     // with a single attribute "value=" set to the passed value.
  100.     void addElem(QDomElement& addTo, QString name, bool value);
  101.     void addElem(QDomElement& addTo, QString name, QString value);
  102.     void addElem(QDomElement& addTo, QString name, int value);
  103.     void addElem(QDomElement& addTo, QString name, double value);
  104.     void addList(QDomElement& addTo, QString name, QList<QString>& value);
  105.  
  106.     // Helper: add the PresentVals data to the document
  107.     void addPresentationData();
  108.     // Helper: Add the LPI settings to the document
  109.     void addLPISettings();
  110.  
  111.     // Helper: set the `opts' members from the current DOM tree
  112.     bool readSettings();
  113.  
  114.     // Helper functions. Read various single elements into variables
  115.     // All of these return true for success. On failure, the passed
  116.     // value pointer is undefined.
  117.     bool readElem(QDomElement& parent, QString name, bool* value);
  118.     bool readElem(QDomElement& parent, QString name, int* value);
  119.     bool readElem(QDomElement& parent, QString name, double* value);
  120.     bool readElem(QDomElement& parent, QString name, QString* value);
  121.     bool readList(QDomElement& parent, QString name, QList<QString>* value);
  122.  
  123.     bool readPDFVersion();
  124.     bool readPresentationData();
  125.     bool readLPISettings();
  126.  
  127.     // Returns the named node under `parent' iff it's unique
  128.     QDomNode getUniqueNode(QDomElement& parent, QString name);
  129.  
  130.     // Return a QDomElement corresponding to the passed node, ensuring it's a
  131.     // valid element, the only one of its name under `parent', it has name
  132.     // `name', and (by default) has a `value' attribute.
  133.     QDomElement getValueElement(QDomNode& node, QString name, bool isValue = true);
  134.  
  135.     // The QDomDocument used by the class for all its XML work
  136.     QDomDocument m_doc;
  137.     // The root element
  138.     QDomElement m_root;
  139.     // The PDFOptions instance we're operating on
  140.     PDFOptions* m_opts;
  141.     // Whether to save passwords when writing out settings
  142.     bool m_includePasswords;
  143.  
  144.     // Version, of the form Mmpr: Major, minor, patch, revision
  145.     // eg 1300 - 1.3.0r0
  146.     static const int formatVersion;
  147.  
  148.     // Error explanation if a function fails
  149.     // For user only, do not depend on particular values of this.
  150.     QString m_error;
  151. };
  152.  
  153. #endif
  154.